package com.chap17;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * <p>
 * <code>FutureDemo</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-05-05 14:50
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
@Slf4j
public class FutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        new Thread(()->{
            log.debug("通过 runnable 方式执行任务");
        }).start();

        FutureTask task = new FutureTask(new Callable() {
            @Override
            public Object call() throws Exception {
                log.debug("通过callable方式执行任务");
                Thread.sleep(3000);
                return "返回任务结果";
            }
        });

        new Thread(task).start();
        log.debug("结果：{}",task.get());
    }
}
